// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import VueRouter from 'vue-router'
import routes from './router'
import ElementUI from 'element-ui'
import FastClick from 'fastclick'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import Utils from './assets/utils/index'
import config from '../config'
import 'element-ui/lib/theme-default/index.css'

Vue.use(VueRouter)
Vue.use(ElementUI)
Vue.use(Utils)

FastClick.attach(document.body)

const router = new VueRouter({
  mode: 'history',
  base: config.build.assetsPublicPath,
  routes: routes
})

import store from './vuex/store'

// white user list
// const whiteList = ['/login', '/index']
router.beforeEach((to, from, next) => {
  // 顶部加载条
  NProgress.start()
  // TODO 缺失验证访问权限
  if (routes[3].children && routes[3].children.find((x) => x.path === to.path)) {
    // 从menuData中取名称
    // let menuList =window.$globalHub.$store.
    store.commit('ADD_MENU', {name: '', path: to.fullPath})
    next()
  } else {
    next()
  }
})
router.afterEach(() => {
  setTimeout(function () {
    NProgress.done()
  }, 1000)
})

/* eslint-disable no-new */
window.$globalHub = new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#root')
